﻿Create proc ThemSP
(
	@Masp nvarchar (8),
	@MaLoaisp int,
	@Madvt int,
	@Tensp nvarchar(50),
	@Dongia numeric,
	@Mota Nvarchar (100)
)as
	Insert into SANPHAM values(@Masp,@MaLoaisp,@Madvt,@Tensp,@Dongia,@Mota)

Create proc SuaSP
(
	@Masp nvarchar (8),
	@MaLoaisp int,
	@Madvt int,
	@Tensp nvarchar(50),
	@Dongia numeric,
	@Mota Nvarchar (100)
)as
	update SANPHAM set Maloaisp=@Maloaisp,Madvt=@Madvt,Tensp=@Tensp,Dongia=@Dongia,Mota=@Mota where Masp=@Masp
----------------Don Vi Tính --------------------------
Create Proc ThemDVT
(
	@Tendvt Nvarchar(30)
)as
	Insert into DonViTinh values(@TenDVT) 
Create proc SuaDVT
(
	@Madvt int,
	@Tendvt Nvarchar(30)
)as
	update DONVITINH set Tendvt=@Tendvt where Madvt=@Madvt

Create Proc XoaDVT
(
	@Madvt int
)as
	Delete DONVITINH where Madvt=@Madvt
--------------Thêm Nhân Viên---------------------------
Create Proc ThemNV
(
	@Tennv Nvarchar(50)
)as
	Insert into NhanVien values(@TenNV) 

Create proc SuaNV
(
	@Manv int,
	@Tennv Nvarchar(50)
)as
	update NhanVien set Tennv=@Tennv where Manv=@Manv

Create Proc XoaNV
(
	@Manv int
)as
	Delete NhanVien where Manv=@Manv
--------------------Nhà cung cấp-----------------------------
Create Proc ThemNCC
(
	@Tenncc Nvarchar(50),
	@Diachi nvarchar(100),
	@Dienthoai nvarchar (30)
)as
	Insert into NHACUNGCAP values(@Tenncc,@Diachi,@Dienthoai) 

Create proc SuaNCC
(
	@Mancc int,
	@Tenncc Nvarchar(50),
	@Diachi nvarchar(100),
	@Dienthoai nvarchar (30)
)as
	update NHACUNGCAP set Tenncc=@Tenncc,Diachi=@Diachi,Dienthoai=@Dienthoai where Mancc=@Mancc

Create Proc XoaNCC
(
	@Mancc int
)as
	Delete NHACUNGCAP where Mancc=@Mancc
------------------ Phiếu Nhập ---------------------------------------
Create Proc ThemPN
(
	@Mapn nvarchar(10),
	@Manv int,
	@Mancc int,
	@Ngaynhap datetime,
	@Lydo nvarchar(100),
	@TongSL numeric,
	@TongTien Numeric
)as
	Insert into PhieuNhap values(@Mapn,@Manv,@Mancc,@Ngaynhap,@Lydo,@TongSL,@TongTien)
--------------------CT Phiếu Nhập ------------------------------------------
Create Proc ThemCTPN
(
	@Mapn nvarchar (10),
	@Masp Nvarchar (8),
	@soluong int,
	@DVT nvarchar (30),
	@Dongia int,
	@Thanhtien int
)as
	Insert into CTPHIEUNHAP values (@Mapn,@Masp,@soluong,@DVT,@Dongia,@Thanhtien)
Create Proc SuaCTPN
(
	@Mapn nvarchar (10),
	@Masp Nvarchar (8),
	@soluong int,
	@DVT nvarchar (30),
	@Dongia int,
	@Thanhtien int
)as
	Update CTPHIEUNHAP set Masp=@Masp,Soluong=@soluong,DVT=@DVT,Dongia=@Dongia,Thanhtien=@Thanhtien where Mapn=@Mapn and Masp=@Masp
go
Create Proc XoaCTPN
(
	@Mapn nvarchar (10),
	@Masp Nvarchar (8)
)as
	Delete CTPhieuNhap where Mapn=@Mapn and Masp=@Masp
go
-------------Hóa Đơn ---------------------------
Create Proc ThemHD
(
	@Mahd nvarchar(10),
	@Manv int,
	@Tenkh nvarchar(50),
	@Ngaylap datetime,
	@Ghichu nvarchar(100),
	@TongSL int,
	@TongTien Numeric
)as
	Insert into HoaDon values(@Mahd,@Manv,@Tenkh,@Ngaylap,@Ghichu,@TongSL,@TongTien)
go

------------------
Create Proc ThemCTHD
(
	@Mahd nvarchar(10),
	@Masp nvarchar(8),
	@Soluong int,
	@DVT nvarchar(30),
	@Dongia numeric,
	@Thanhtien Numeric
)as
	Insert into CTHoaDon values(@Mahd,@Masp,@soluong,@DVT,@Dongia,@Thanhtien)
go
Create Proc SuaCTHD
(
	@Mahd nvarchar(10),
	@Masp nvarchar(8),
	@Soluong int,
	@DVT nvarchar(30),
	@Dongia numeric,
	@Thanhtien Numeric
)as
	Update CTHoaDon set Mahd=@Mahd,Masp=@Masp,soluong=@soluong,DVT=@DVT,Dongia=@Dongia,Thanhtien=@Thanhtien where Mahd=@Mahd and Masp=@Masp
go
Create Proc XoaCTHD
(
	@Mahd nvarchar (10),
	@Masp Nvarchar (8)
)as
	Delete CTHoaDon where Mahd=@Mahd and Masp=@Masp
go